<template>
	<view>
		<view class="" v-if="Object.keys(items).length > 0">
			<img :src="items.thumb" alt="" style="width:100%;max-height: 400rpx">
		</view>
		<view class=""
			style="display: flex;justify-content: space-between;padding: 20rpx;font-size: 32rpx;align-items: center;flex-wrap: wrap;">
			<view class="" style="max-width: 70%;font-weight: bold;">
				{{items.title}}
			</view>
			<view class="" style="font-size: 28rpx;text-align: right;width: 100%;margin-top: 10rpx">
				{{items.begintime}}到{{items.endtime}}
			</view>
		</view>
		<view class="" style="padding: 20rpx;">
			<rich-text :nodes="items.content" @itemclick="onLinkPress"></rich-text>
		</view>
		<view style="height: 120rpx;" :style="'padding-bottom: '+(bottomHight - 20)+'px;'"></view>
		<view class="wid100 bacFFF poFix" style="bottom: 0;">
			<view class="dis disAl" style="height: 120rpx;">
				<view class="hei80 wid90 mar borRad10 dis disAl disJuC foSi30 coFFF" 
					style="background-color: #035DFF;" @click.stop="show_contacts_ewm()">立即沟通</view>
			</view>
			<!-- <view class="dis disAl" style="height: 120rpx;">
				<view class="hei80 wid90 mar borRad10 dis disAl disJuC foSi30 coFFF" 
					style="background-color: #035DFF;" @click.stop="baoming(items.id,items.companyid)">报名</view>
			</view> -->
			<view v-if="bottomHight != 0" :style="'height: '+(bottomHight - 20)+'px;'"></view>
		</view>
		<uni-popup ref="popup" type="bottom" border-radius="10px 10px 0 0">
			<view class="" style="background-color: #fff;padding: 30rpx;border-radius: 15rpx;align-items: center;display: flex;flex-direction: column;">
				<image :src="url+items.contacts_ewm" mode="" style="width: 400rpx;height: 400rpx;"></image>
				<view class="" style="margin-top:20rpx;color: #565656;">
					长按图片保存
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		Notice
	} from '../../model/notice-model.js';
	var notice = new Notice();
	import { Config } from '../../utils/config.js';
	export default {
		data() {
			return {
				url: Config.restUrl,
				items: {},
				bottomHight: 0
			}
		},
		onLoad(option) {
			console.log(option)
			let app = uni.getSystemInfoSync();
			this.bottomHight = app.safeAreaInsets.bottom //屏幕底部安全距离
			this.getdata(option.id)
		},
		methods: {
			onLinkPress(e) {
				console.log(e.detail.node.attrs.href)
				window.location.href = e.detail.node.attrs.href
			},
			show_contacts_ewm(){
				// 提示二维码
				this.$refs.popup.open('center')
			},
			baoming(id, companyid) {
				var that = this
				if(!uni.getStorageSync('token')){
					return uni.navigateTo({
						url:'/pages/login/index'
					})
				}
				let params = {
					aid: id,
					companyid: companyid
				}
				uni.showModal({
					title: '提示',
					content: '确认报名该招聘吗',
					success: (res) => {
						if (res.confirm) {
							notice.signupActive((data) => {
								console.log(data)
								if (data.code === 0) {
									uni.showToast({
										title: '报名成功',
										icon: 'none',
										duration: 2000
									})
									that.getlist()
								} else {
									uni.showToast({
										title: data.msg,
										icon: 'none',
										duration: 2000
									})
								}
							}, params)
						} else if (res.cancel) {
							// 用户点击了取消按钮
							console.log('用户取消了授权');
						}
					}
				});
			
			},
			getdata(id) {
				var that = this
				let params = {
					id: id
				}
				notice.activeDetails((data) => {
					console.log(data)
					if (data.code === 0) {
						that.items = data.data
						that.items.content = that.items.content.replace(/<img/gi, "<img class='richImg'");
						that.items.content = that.items.content.replace(/color="/gi, 'style="color:');
					} else {
						uni.showToast({
							title: data.msg,
							icon: 'none',
							duration: 2000
						})
					}
				}, params)
			}
		}
	}
</script>

<style>
	page {
		background-color: #fff;
	}

	.rich {
		word-break: break-all;
		white-space: pre-warp;
	}

	.richImg {
		width: 100% !important;
		height: auto !important;
	}
</style>